package com.example.user.service;


import com.example.user.common.Result;
import com.example.user.entity.AddressManagement;
import com.example.user.mapper.AddressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressService {



    @Autowired
    private AddressMapper addressMapper;

    public List<AddressManagement> getAdderssPage() {

       List<AddressManagement> addressManagementList= addressMapper.getAddressManagement();
       return addressManagementList;

    }

    public Result updateAddress(AddressManagement addressManagement) {

        int count = addressMapper.updateAddress(addressManagement);
        if(count==0)
        {
            return Result.error("400","修改失败");
        }
        return Result.success("修改成功");
    }

    public Result addAdderss(AddressManagement addressManagement) {
       int count= addressMapper.addAddress(addressManagement);
       if(count==0)
       {
           return  Result.error("400","增加失败");
       }

       return Result.success("增加成功");
    }

    public Result deleteById(Integer id) {
        int count= addressMapper.deleteById(id);
        if(count==0)
        {
            return Result.error("400","删除失败");
        }
        return Result.success("删除成功");
    }
}
